<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="utf-8">
		<title>用户认证审批</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" th:href="@{/center/lib/layui-v2.5.5/css/layui.css}" media="all">
		<link rel="stylesheet" th:href="@{/center/css/public.css}" media="all">
		<script th:src="@{/center/lib/layui-v2.5.5/layui.js}" charset="utf-8"></script>
		
			<script th:inline="none">
				layui.use(['form', 'table'], function() {
					var $ = layui.jquery,
						form = layui.form,
						table = layui.table;
		
		
					var tableIns = null;
		
					// 监听搜索操作
					//多条件查询
					form.on('submit(data-search-btn)', function(data) {
						var jsonstr = JSON.stringify(data.field);
						console.log(jsonstr);
						tableIns = table.render({
							elem: '#currentTableId',
							url: '/center/showAllUserApply',
							method: "post",
							contentType: 'application/json;charset=utf-8',
		
							initSort: {
								field: 'center_usertype',
								type: 'desc'
							},
							toolbar: '#toolbarDemo',
							defaultToolbar: ['filter', 'exports', 'print', {
								title: '提示',
								layEvent: 'LAYTABLE_TIPS',
								icon: 'layui-icon-tips'
							}],
							cols: [
								[{
										title: '审核',
										width: 200,
										toolbar: '#currentTableBar',
										align: "center"
									},{
										field: 'photo',
										width: 120,
										title: '用户照片',
										templet:"#phototemp"
									
										
									},
									{
										field: 'center_verifydata',
										width: 120,
										title: '证件照片',
										templet:"#verifytemp"
									},
									{
										field: 'name',
										width: 100,
										title: '用户名',
										sort: true
									},
									{
										field: 'nickname',
										width: 100,
										title: '昵称',
										sort: true
									},
									
									{
										field: 'phone',
										width: 140,
										title: '用户电话'
									},
									{
										field: 'center_credentialcode',
										width: 160,
										title: '证件号'
									},
									{
										field: 'intro',
										width: 100,
										title: '用户简介',
										sort: true
									},
									{
										field: 'center_usertype',
										width: 100,
										title: '用户类型',
										templet:function(d){
											if(d.center_usertype=='1'){
												return '业主'
											}else if(d.center_usertype=='2'){
												return '商家'
											}else if(d.center_usertype=='3'){
												return '物业'
											}
										},
										sort: true
									},
									{
										field: 'id',
										width: 100,
										title: '用户ID',
									}
								]
							],
							page: false,
							skin: 'row'
						});
		
						return false;
					});
		
					//监听审批
					table.on('tool(currentTableFilter)', function(obj) {
						var data = obj.data;
						
						if (obj.event === 'pass') { //监听通过操作
							layer.confirm('是否确定通过审核?', function(index) {
								$.ajax({
									url: '/center/passUserApply',
									contentType: 'application/json;charset=utf-8',
									method: 'POST',
									data:data.id,
									success: function(res) {
										console.log("前端接收到的回调:" + res);
										tableIns.reload();
										layer.alert(res.msg);
		
									}
								});
		
								layer.close(index);
							});
							return false;
						} else if (obj.event === 'reject') { //监听拒绝操作
							layer.confirm('是否确定拒绝?', function(index) {
								$.ajax({
									url: '/center/rejectUserApply',
									contentType: 'application/json;charset=utf-8',
									method: 'POST',
									data:data.id,
									success: function(res) {
										tableIns.reload();
										layer.alert(res.msg);
		
									}
								});
		
								layer.close(index);
							});
						} else if (obj.event === 'verify') { //监听拒绝操作
							layer.confirm('是否开始实名验证?', function(index) {
								$.ajax({
									url: '/center/realNameCertification',
									contentType: 'application/json;charset=utf-8',
									method: 'POST',
									data:JSON.stringify( {'id':data.id,'name':data.name,'phone':data.phone,'center_usertype':data.center_usertype,'center_credentialcode':data.center_credentialcode}),
									success: function(res) {
										tableIns.reload();
										layer.alert(res.msg);
		
									}
								});
		
								layer.close(index);
							});
						}
					});
		
		
				});
			
			</script>
			<!-- 图片单元格模板 -->
			<script type="text/html" id="phototemp" th:inline="javascript">
				<img src="{{d.photo}}"/>
		</script>
			<script type="text/html" id="verifytemp" th:inline="javascript">
				<img src="{{d.center_verifydata}}" />
		</script>
		<!-- 配合图片大小自适应表格高度 -->
		<style>
			.layui-table-cell {
		            height: 100%;
		            max-width: 100%;
		        }
		</style>

	</head>


	<body>
		<div class="layuimini-container">
			<div class="layuimini-main">

				<fieldset class="table-search-fieldset">
					<legend>查询待审批用户认证</legend>
					<div style="margin: 10px 10px 10px 10px">
						<div class="layui-inline">
							<button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i>
								查询
							</button>
						</div>
					</div>
					</form>
				</fieldset>
			</div>



			<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

			<script type="text/html" id="currentTableBar">
				<a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="pass">通过</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="reject">不通过</a>
				 <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="verify">认证实名</a>
    </script>

		</div>
		</div>
	


	</body>
</html>
